package com.itheima.controller;

import com.itheima.aop.MyLog;
import com.itheima.dto.EmpListDto;
import com.itheima.page.PageBean;
import com.itheima.pojo.Emp;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import com.itheima.service.ReportService;
import com.itheima.vo.GetJobListVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/emps")
@RestController
@Slf4j
public class EmpController {

    @Autowired
    EmpService empService;

    @GetMapping
   public Result list(EmpListDto empListDto){
        log.info("接受的参数为:{}",empListDto);
        PageBean pageBean = empService.list(empListDto);
        return Result.success(pageBean);
    }
    @MyLog
    @PostMapping
    public Result insert(@RequestBody Emp emp){
        log.info("传进来的参数:{}",emp);
        empService.insert(emp);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        log.info("传过来的ids为:{}",ids);
        empService.deleteByIds(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("根据id查询员工的详细信息");
        Emp emp  = empService.getInfo(id);
        return Result.success(emp);
    }

    @PutMapping
    public Result update(@RequestBody Emp emp){
        empService.update(emp);
        return Result.success();
    }
}
